package com.swm.util1;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.swm.pojo.Stock_Day_Data;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 师文明
 * @data 2025/5/10 上午9:58
 **/
public class ConditionUtil {
    //2010年 3200条


    //获取最近价格稳定是否存在
    public static boolean getPriceAmplitude(List list, int startDay, int beforeDay) {

        double maxprice = 0;
        double minprice = 10000;
        boolean priceflag = false;
        //十天振幅
        String [] split = list.get(startDay+1).toString().split(",");
        double price0= Double.parseDouble(split[2]);

        for (int i = startDay + 1; i < (startDay + beforeDay) + 1; i++) {
            String [] spliti = list.get(i).toString().split(",");
            double price= Double.parseDouble(spliti[2]);
            maxprice = Math.max(price, maxprice);
            minprice = Math.min(price, minprice);
        }
        double priceDiff = (maxprice - minprice) / price0;
        if (priceDiff < 0.1) {
            priceflag = true;
        }

        return priceflag;
    }

    //近120天 价格处于低位
    public static boolean getPriceBL(List list, int startDay,int big, int little) {
        //最近120天内收盘价集合
        List<Double> prices = new ArrayList<>();
        String [] split = list.get(startDay).toString().split(",");
        double s2= Double.parseDouble(split[2]);

        for (int j = 0; j < big; j++) {
            //收盘价
            String [] splitj = list.get(startDay + j).toString().split(",");
            double p2= Double.parseDouble(splitj[2]);
            prices.add(p2);
        }
        // 使用List的sort()方法和Lambda表达式进行排序
        prices.sort(Double::compare);
        return s2 < prices.get(little)/*s1==prices.get(0)*/;
    }

    //近120天 成交量处于高位
    public static boolean getMoneyBL(List list, int startDay,int big, int little) {
        //最近120天内收盘价集合
        List<Double> moneys = new ArrayList<>();
        String [] split = list.get(startDay).toString().split(",");
        double s2= Double.parseDouble(split[5]);

        for (int j = 0; j < big; j++) {
            //收盘价
            String [] splitj = list.get(startDay + j).toString().split(",");
            double p2= Double.parseDouble(splitj[5]);
            moneys.add(p2);
        }
        // 使用List的sort()方法和Lambda表达式进行排序
        moneys.sort(Double::compare);

        return s2 > moneys.get(little)/*s1==prices.get(0)*/;
    }

    //获取所有均线
    public static JSONObject getLines(List list, int startDay) {
        //日线
        double totalsix1 = 0.0;
        double totalth1 = 0.0;
        double totaltw1 = 0.0;
        double totalte1 = 0.0;
        double totalf1 = 0.0;
        for (int j = 0; j < 60; j++) {
            String [] split = list.get(startDay+j).toString().split(",");
            double price= Double.parseDouble(split[2]);

            if (j < 5) {
                totalf1 += price;
            }
            if (j < 10) {
                totalte1 += price;
            }
            if (j < 20) {
                totaltw1 += price;

            }
            if (j < 30) {
                totalth1 += price;

            }
            totalsix1 += price;

        }
        double six1 = totalsix1 / 60;
        double th1 = totalth1 / 30;
        double tw1 = totaltw1 / 20;
        double te1 = totalte1 / 10;
        double f1 = totalf1 / 5;
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("f1", f1);
        jsonObject.put("te1", te1);
        jsonObject.put("tw1", tw1);
        jsonObject.put("th1", th1);
        jsonObject.put("six1", six1);
        return jsonObject;

    }

    //获取所有均线
    public static double getLinesDay(List list, int startDay,int days) {
        //日线
        double total = 0.0;

        for (int j = 0; j < days; j++) {
            String [] split = list.get(startDay+j).toString().split(",");
            double price= Double.parseDouble(split[2]);
            total += price;
        }
        return total / days;

    }

    //获取几天内最大价格
    public static double getMaxPrice(List list, int startDay, int days) {
        //最近120天内成交量集合
        double max = 0;
        for (int j = 1; j < days; j++) {
            //收盘价
            String [] split = list.get(startDay + j).toString().split(",");
            double p2= Double.parseDouble(split[3]);
            max = Math.max(p2, max);
        }
        return max;
    }
    //获取几天平均成交量
    public static double getAverageMoney(List list,int days,int begday){
        double total=0;
        for(int i=0;i<days;i++){
            String [] split = list.get(i+begday).toString().split(",");
            double money= Double.parseDouble(split[5]);
            total+=money;
        }
        return total / days;
    }

    //近120天 价格处于低位
    public static boolean getPrice12010(JSONArray klines, int startDay,int big, int little) {
        //最近120天内收盘价集合
        List<Double> prices = new ArrayList<>();
        double s1 = Double.parseDouble(klines.get(klines.size() - startDay - 1).toString().split(",")[2]);
        double s2 = Double.parseDouble(klines.get(klines.size() - startDay).toString().split(",")[2]);
        for (int j = 0; j < big; j++) {
            //收盘价
            double p2 = Double.parseDouble(klines.get(klines.size() - (startDay + j)).toString().split(",")[2]);
            prices.add(p2);
        }
        // 使用List的sort()方法和Lambda表达式进行排序
        prices.sort(Double::compare);
        return s1 < prices.get(little)/*&&s1>prices.get(5)*/;
    }

    //近120天 成交量处于高位
    public static boolean getMoney(JSONArray klines, int startDay,int big, int little) {
        //最近120天内成交量集合
        List<Double> numbers = new ArrayList<>();
        double v1 = Double.parseDouble(klines.get(klines.size() - startDay).toString().split(",")[5]);
        for (int j = 0; j < big; j++) {
            //成交量
            double v2 = Double.parseDouble(klines.get(klines.size() - (startDay + j)).toString().split(",")[5]);
            numbers.add(v2);
        }
        // 使用List的sort()方法和Lambda表达式进行排序
        numbers.sort(Double::compare);
        return v1 > numbers.get(little);
    }


}
